import os
import sys

#Houdini paths and names
HOU_DEV_FILE_NAME = "dev.hipnc"
HOU_EVALA_FILE_NAME = "evalA.hipnc"
HOU_EVALB_FILE_NAME = "evalB.hipnc"
SCORE_ATTRIB_NAME = "score"
GENOTYPE_NODE_PATH = "/obj/DEXEN/GENOTYPE"
PHENOTYPE_NODE_PATH = "/obj/DEXEN/PHENOTYPE"
SCORE_NODE_PATH = "/obj/DEXEN/SCORE"
HOU_FOLDER_NAME = "houdini_files"
HOU_FOLDER_PATH = os.path.join(os.getcwd(), HOU_FOLDER_NAME)

#Function to set up houdini correctly#\
#http://www.sidefx.com/docs/houdini11.0/hom/commandline
def enable_hou_module():
    '''Set up the environment so that "import hou" works.'''
    # Importing hou will load in Houdini's libraries and initialize Houdini.
    # In turn, Houdini will load any HDK extensions written in C++.  These
    # extensions need to link against Houdini's libraries, so we need to
    # make sure that the symbols from Houdini's libraries are visible to
    # other libraries that Houdini loads.  So, we adjust Python's dlopen
    # flags before importing hou.
    if hasattr(sys, "setdlopenflags"):
        old_dlopen_flags = sys.getdlopenflags()
        import DLFCN
        sys.setdlopenflags(old_dlopen_flags | DLFCN.RTLD_GLOBAL)

    try:
        import hou
    except ImportError:
        # Add $HFS/houdini/python2.5libs to sys.path so Python can find the
        # hou module.
        sys.path.append( os.environ['HFS'] + "/houdini/python%d.%dlibs" % sys.version_info[:2])
        import hou
    finally:
        if hasattr(sys, "setdlopenflags"):
            sys.setdlopenflags(old_dlopen_flags)

#Function to create empty folder
def create_folder(folder_path):
    if not os.path.exists(folder_path):
        os.mkdir(folder_path)
    else:
        for the_file in os.listdir(folder_path):
            file_path = os.path.join(folder_path, the_file)
            try:
                if os.path.isfile(file_path):
                    os.unlink(file_path)
            except Exception, e:
                print e